<?php
/**---------------------------------------------------------------------------
 * Purpose：	CommonCls
 * 
 * CreateDate : 2013/01/19
 * Description：
 * 	データベースの接続、選択などの一連の処理を行なう
 *  Connect to database and run query statement.
 * @package	C-UNIT Class
 * @author	 C-UNIT SQUARE CO.,LTD. <info@c-unit.co.jp>
 * @copyright  Copyright(c) 2013　C-UNIT SQUARE CO.,LTD. All Rights Reserved.
 * @license	C-UNIT SQUARE CO.,LTD.
 ---------------------------------------------------------------------------*/
class CUnit_CommonCls
{
	 /*---------------------------------------------------
	  * Convert Han kaku to Jen kaku
	  * @param 	string	$strConvertString	Convert string
	  * @return	string	$strResult			String is converted
	  ---------------------------------------------------*/
	 function han_kaku_to_jen_kaku($strConvertString){
		$arrReplaceOf = array('ｳﾞ','ｶﾞ','ｷﾞ','ｸﾞ',
							'ｹﾞ','ｺﾞ','ｻﾞ','ｼﾞ',
							'ｽﾞ','ｾﾞ','ｿﾞ','ﾀﾞ',
							'ﾁﾞ','ﾂﾞ','ﾃﾞ','ﾄﾞ',
							'ﾊﾞ','ﾋﾞ','ﾌﾞ','ﾍﾞ',
							'ﾎﾞ','ﾊﾟ','ﾋﾟ','ﾌﾟ','ﾍﾟ','ﾎﾟ');
		$arrReplaceBy = array('ヴ','ガ','ギ','グ',
							'ゲ','ゴ','ザ','ジ',
							'ズ','ゼ','ゾ','ダ',
							'ヂ','ヅ','デ','ド',
							'バ','ビ','ブ','ベ',
							'ボ','パ','ピ','プ','ペ','ポ');
		$strResult = str_replace($arrReplaceOf, $arrReplaceBy, $strConvertString);
		
		$arrReplaceOf = array('ｱ','ｲ','ｳ','ｴ','ｵ',
							'ｶ','ｷ','ｸ','ｹ','ｺ',
							'ｻ','ｼ','ｽ','ｾ','ｿ',
							'ﾀ','ﾁ','ﾂ','ﾃ','ﾄ',
							'ﾅ','ﾆ','ﾇ','ﾈ','ﾉ',
							'ﾊ','ﾋ','ﾌ','ﾍ','ﾎ',
							'ﾏ','ﾐ','ﾑ','ﾒ','ﾓ',
							'ﾔ','ﾕ','ﾖ','ﾗ','ﾘ',
							'ﾙ','ﾚ','ﾛ','ﾜ','ｦ',
							'ﾝ','ｧ','ｨ','ｩ','ｪ',
							'ｫ','ヵ','ヶ','ｬ','ｭ',
							'ｮ','ｯ','､','｡','ｰ',
							'｢','｣','ﾞ','ﾟ');
		$arrReplaceBy = array('ア','イ','ウ','エ','オ',
							'カ','キ','ク','ケ','コ',
							'サ','シ','ス','セ','ソ',
							'タ','チ','ツ','テ','ト',
							'ナ','ニ','ヌ','ネ','ノ',
							'ハ','ヒ','フ','ヘ','ホ',
							'マ','ミ','ム','メ','モ',
							'ヤ','ユ','ヨ','ラ','リ',
							'ル','レ','ロ','ワ','ヲ',
							'ン','ァ','ィ','ゥ','ェ',
							'ォ','ヶ','ヶ','ャ','ュ',
							'ョ','ッ','、','。','ー',
							'「','」','”','');		
		$strResult = str_replace($arrReplaceOf, $arrReplaceBy, $strResult);
		return $strResult;
	}
	
	/**----------------------------------------------------------------------
	 * send mail
	 * 
	 * @param string	$strMailForm
	 * @param string	$strMailTo
	 * @param string	$strSubject
	 * @param string	$strMailContent
	 * 
	 * @return True/False
	 ------------------------------------------------------------------------*/
	function sendMail($strMailForm, $strMailTo, $strSubject = '(No subject)', $strMailContent = '')
	{
		// content mail						
		$strSubject = mb_convert_encoding($strSubject, 'ISO-2022-JP-MS', 'utf-8');
		$strSubject = "=?ISO-2022-JP?B?" . base64_encode($strSubject) . '?=';
		$strMailContent = str_replace("\n", '<BR>', $strMailContent);
		$strMailContent = mb_convert_encoding($strMailContent, 'ISO-2022-JP-MS', 'utf-8');

		$objMail = new Zend_Mail('ISO-2022-JP');
		$arrMailTo = explode(",", $strMailTo)	;	
		try{
			$objMail->setBodyHtml($strMailContent);
			$objMail->setFrom($strMailForm);
			foreach($arrMailTo as $intKey => $strEmail){
				$objMail->addTo($strEmail);
			}			
			$objMail->setSubject($strSubject);
			return $objMail->send();
		}catch (Exception $e){
			//echo $e->getMessage();
		}
		return false;
	}
	
	/**----------------------------------------------------------------------
	 * check input data is Katakana character
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkKatakana($strText, $byte = 'all')
	{
		$strText = mb_convert_encoding($strText, 'UTF-8', 'auto');
		
		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if($byte == '1')
		   {
		   	   if (!($this->is_half_katakana($char)) && ($char != " ") && ($char != "　"))
			   {
					return false;
			   }
		   }
		   else if($byte == '2')
		   {
		   	   if (!($this->is_full_katakana($char)) && ($char != " ") && ($char != "　"))
			   {
					return false;
			   }
		   }
		   else
		   {
		   	   if (!($this->is_katakana($char)) && ($char != " ") && ($char != "　"))
			   {
					return false;
			   }	
		   }
		} 
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * check input data is Hiragana character
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkHiragana($strText)
	{
		$strText = @mb_convert_encoding($strText, 'UTF-8', 'auto');

		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if (!($this->is_hiragana($char)) && ($char != " ") && ($char != "　"))
		   {
				return false;
		   }
		}
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * check input data is Kanji character
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkKanji($strText)
	{
		$strText = mb_convert_encoding($strText, 'UTF-8', 'auto');
		
		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if (!($this->is_kanji($char)) && ($char != " ") && ($char != "　"))
			{
				return false;
			}
		} 
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * check input data is Japanese character (include Katakana, Hiragana and Kanji)
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkJapaneseCharset($strText)
	{
		$strText = mb_convert_encoding($strText, 'UTF-8', 'auto');
		
		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if (!($this->is_japanese($char)) && ($char != " ") && ($char != "　"))
			{
				return false;
			}
		}
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * check input data is Japanese character (include Katakana 2 byte, Hiragana and Kanji)
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkJapaneseCharset2byte($strText)
	{
		$strText = mb_convert_encoding($strText, 'UTF-8', 'auto');
		
		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if (!($this->is_japanese2byte($char)) && ($char != " ") && ($char != "　"))
			{
				return false;
			}
		}
		return true;
	}
	
	 /**----------------------------------------------------------------------
	 * check input data is Japanese character (Katakana 2 byte)
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function checkTextFuriganaControl($strText)
	{
		$strText = mb_convert_encoding($strText, 'UTF-8', 'auto');
		
		$len   = mb_strlen( $strText);
		
		for( $idx = 0; $idx < $len; $idx++)
		{
		   $char = mb_substr( $strText, $idx, 1);
		   if (!($this->is_TextFuriganaControl($char)) && ($char != " ") && ($char != "　"))
			{
				return false;
			}
		}
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * Check if the given string is Japanese
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	private function is_japanese(&$value)
	 {
		 $bc =0;
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			 $c = mb_substr($value,$i,1);
			 if (!$this->is_kanji($c)
					 && !$this->is_hiragana($c)
					 && !$this->is_katakana($c) )
			 {
				  return false;
			 }
		 }
		 return true;
	  }
	  
	/**----------------------------------------------------------------------
	 * Check if the given string is Japanese
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	private function is_japanese2byte(&$value)
	 {
		 $bc =0;
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			 $c = mb_substr($value,$i,1);
			 if (!$this->is_kanji($c)
					 && !$this->is_hiragana($c)
					 && !$this->is_full_katakana($c)
					 && !$this->isAlphaNumberic($c))
			 {
			  	  return false;			  		  
			 }
		 }
		 return true;
	  }
	  
	 /* Check if the given string is Japanese
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	private function is_TextFuriganaControl(&$value)
	 {
		 $bc =0;
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			 $c = mb_substr($value,$i,1);
			 if (!$this->is_full_katakana($c)
			 		&& !$this->isAlphaNumberic($c))
			 {
				  return false;
			 }
		 }
		 return true;
	  }

	/**----------------------------------------------------------------------
	 * Check if the given character is katakana
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	 private function is_katakana($value)
	 {
		 return ($this->is_half_katakana($value) || $this->is_full_katakana($value));
	 }
	
	/**----------------------------------------------------------------------
	 * Check if the given character is hiragana
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	private function is_hiragana($value)
	{
		for ($i = 0; $i < mb_strlen($value) ; $i++)
		{	
			$c = mb_substr($value,$i,1);

			$c = $this->utf8_ord($c,$bc);

			// 0x30fc = 「ー」 (katakana)
			if (!(((0x3040 <= $c) && ($c <= 0x309e)) || ($c == 0x30fc)))
			{
				return false;
			}
		}
	
		return true;
	}

	 /**----------------------------------------------------------------------
	 * Check if the given character is half katakana
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	 private function is_half_katakana($value)
	 {
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			  $c = mb_substr($value,$i,1);
			  $c = $this->utf8_ord($c,$bc);
			  if (!((0xff66 <= $c) && ($c <= 0xff9d)))
			  {
					return false;
			  }
		 }
		 return true;
	 }

	 /**----------------------------------------------------------------------
	 * Check if the given character is full katakana
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	 private function is_full_katakana($value)
	 {
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			 $c = mb_substr($value,$i,1);
			 $c = $this->utf8_ord($c,$bc);
			 if (!((0x30a1 <= $c) && ($c <= 0x30fe)))
			 {
				 return false;
			 }
		 }
		 return true;
	 }

	 /**----------------------------------------------------------------------
	 * Check if the given character is Kanji
	 *
	 * @return   boolean  
	 *
	 ----------------------------------------------------------------------*/
	 function is_kanji($value)
	 {
		 for ($i = 0; $i < mb_strlen($value) ; $i++)
		 {
			 $c = mb_substr($value,$i,1);
			 $c = $this->utf8_ord($c,$bc);
			 $charIsKanji = false;

			 if ((0x4e00 <= $c) && ($c <= 0x9fa5))
			 {
				 $charIsKanji = true;
			 }

			 if ((0x3005 <= $c) && ($c <= 0x3007))
			 {
				 $charIsKanji = true;
			 }
 
			 if (!$charIsKanji)
			 {
				 return false;
			 }
		 }
		 return true;
	 }
	 
	 /**----------------------------------------------------------------------
	 * check input data is alphanumeric
	 *
	 * @return   string if true return string empty, if false return error message  
	 *
	 ----------------------------------------------------------------------*/
	public function isAlphaNumberic($value)
	{
		$pattern = "/[A-Za-z0-9]/";
		if (!preg_match($pattern,$value))
		{
			return false;
		}
		
		return true;
	}
 
 	/**----------------------------------------------------------------------
	 * convert character to hex type
	 *
	 * @return   string  
	 *
	 ----------------------------------------------------------------------*/
	 private function utf8_ord(&$str, &$len, $pos=0, $hex=false)	 
	 {
		  $ord = ord($str{$pos});
		  $len = 1;

		  if ($ord > 0x80)
		  {
			 for ($bc=-1, $mbs=$ord; $mbs & 0x80; $mbs = $mbs << 1)  
			  	$bc++;  // calculate number of extra bytes
			 $len += $bc;

			 $ord = $ord & ((1 << (6-$bc)) - 1);	 // mask utf-8 lead-in bytes

   			 for ($i=$pos+1; $bc; $bc--, $i++)	   // "bring in" data bytes
				  $ord = ($ord << 6) | (ord($str{$i}) & 0x3F);
		  }

		  return $hex ? 'x'.dechex($ord) : $ord;

	}
	
	/**----------------------------------------------------------------------
	 * Check valid email string
	 *
	 * @param	string 	$strMail	Email address
	 * @return   bollean	true/false
	 *
	 ----------------------------------------------------------------------*/
	public function validEmailAddress($strMail)
	{
		if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $strMail) == false){
			return false;
		}
		return true;
	}
	
	/**----------------------------------------------------------------------
	 * Check valid owner login id
	 *
	 * @param	string	$strLoginId		Owner login id
	 * @return   boolean	true/false
	 *
	 ----------------------------------------------------------------------*/
	public function validOwnerLoginId($strLoginId)
	{
		if (preg_match("/^[a-zA-Z0-9_-]*$/", $strLoginId) == false){		
			return false;
		}

		return true;
	}
	
	/**----------------------------------------------------------------------
	 * get Max Size Upload
	 *
	 * @return  int Byte Size
	 *
	 ----------------------------------------------------------------------*/
	public function getMaxSizeUpload()
	{
		$objConfig = CUnit_Config::getConfig();
		// max size upload
		if (version_compare(PHP_VERSION, '5.2.12', '>=')) {				
			$arrMaxSizeUpload = array(	'post_max_size' 		=> ini_get('post_max_size'),
									'upload_max_filesize' 	=> ini_get('memory_limit'));
		} else {
			$arrMaxSizeUpload = array(	'post_max_size' 		=> ini_get('post_max_size'),
									'upload_max_filesize' 	=> ini_get('upload_max_filesize'));
		}
		
		foreach($arrMaxSizeUpload as $strKey => $intMaxSize){
			// Convert to bytes
			$intMaxSize = trim($intMaxSize);
			$strLast = strtolower($intMaxSize[strlen($intMaxSize) - 1]);
			switch($strLast) {
				case 'g': // GB
					$intMaxSize = (int)$intMaxSize * 1073741824;
				case 'k': // KB
					$intMaxSize = (int)$intMaxSize * 1024;
				default:  // MB
					$intMaxSize = (int)$intMaxSize * 1048576;
			}
			$arrIntMaxSizeUpload[$strKey] = $intMaxSize;
		}
		$intSizeTemp = min($arrIntMaxSizeUpload['post_max_size'],$arrIntMaxSizeUpload['upload_max_filesize']);
		return $intSizeTemp;
	}
		
	/**-----------------------------------------------------------------------
	 * 
	 * Check phone number
	 * @param string $str
	 * @Return: true/false
	 ------------------------------------------------------------------------*/
	public function validatePhoneNumber($strPhoneNumber)
	{
	   //if(preg_match('/^[0-9\/-]+$/', $strPhoneNumber) == true){
	   if(preg_match('/^[0-9]{1,4}+\-[0-9]{1,4}+\-[0-9]{1,4}+$/', $strPhoneNumber) == true){
			return true;	
	   }
	   return false;
	}
 	
	/**-----------------------------------------------------------------------
	 * Check valid date time 
	 *
	 * @param 	string 		$strDate	Date string
	 * @param	string		$strFormat	Date format (default Y-m-d H:i:s)
	 * @Return: true/false
	 ------------------------------------------------------------------------*/
	function validateDateTime($strDate, $strFormat = 'Y-m-d H:i:s')
	{
		$objDate = DateTime::createFromFormat($strFormat, $strDate);
		if($objDate != false && $objDate->format($strFormat) == $strDate){
			return true;
		}
		return false;
	}
	
	/**----------------------------------------------------------------------
	* Deletes a directory and all files and folders under it
	* @return Null
	* @param $strFolder String Directory Path
	----------------------------------------------------------------------*/
	public static function  rmdirFiles($strFolder, $strDayCreate = 0) 
	{
		$dh = @opendir($strFolder);
		if ($dh) {
			while($strFile = readdir($dh)) {
				if($strDayCreate != 0){
					if (!in_array($strFile, array('.', '..'))) {
							if (is_file($strFolder . '/' . $strFile)) {
								$intFilelastmodified = filemtime($strFolder . '/' . $strFile);
								if((time() - $intFilelastmodified) > ($strDayCreate*24*3600)){
									@unlink($strFolder . '/' . $strFile);
								}
							} else if (is_dir($strFolder . '/' . $strFile)) {
								CUnit_CommonCls::rmdirFiles($strFolder . '/' . $strFile, $strDayCreate);
							}
						}
					
				} else {
					if (!in_array($strFile, array('.', '..'))) {
						if (is_file($strFolder . '/' . $strFile)) {
							@unlink($strFolder . '/' . $strFile);
						} else if (is_dir($strFolder . '/' . $strFile)) {
							CUnit_CommonCls::rmdirFiles($strFolder . '/' . $strFile, $strDayCreate);
						}
					}
				}
			}
			@rmdir($strFolder);
		}
	}
	
	/**----------------------------------------------------------------------
	* check Name File Upload
	* @param $strNameFile String Name File
	* @param $strPathFile String Path File
	* @param $strFirst String First
	* @param $strLast String Last
	* @param $intIndex intIndex
	* @return new name file
	----------------------------------------------------------------------*/
	public static function checkNameFile($strNameFile, $strPathFile, $strFirst = '_', $strLast = '', $intIndex = 1) 
	{
		if (is_file($strPathFile . '/' . $strNameFile)) {
			$arrNameFile = explode('.', $strNameFile);
			$strNameEx = array_splice($arrNameFile, count($arrNameFile) - 1, 1);
			$strNameEx  = $strNameEx[0];
			unset($arrNameFile[count($arrNameFile)]);
			$strNameFile = implode($arrNameFile);
		
			
			$arrValue = explode($strFirst, $strNameFile);
			$strNameIndex = array_splice($arrValue, count($arrValue) - 1, 1);
			
			if($strLast != ""){
				$strNameIndex = substr($strNameIndex[0], 0, strpos($strNameIndex[0], $strLast));
			} else {
				$strNameIndex = $strNameIndex[0];
			}
			$strValue = implode($arrValue);
			if (false !== $strNameIndex && is_numeric($strNameIndex)) {
				$strNameFile = $strValue;
				$intIndex = (int)$strNameIndex;
			}
			$intIndex ++;
			$strNameFile = $strNameFile . $strFirst . $intIndex . $strLast . '.' . $strNameEx;
			if (is_file($strPathFile . '/' . $strNameFile)) {
				return CUnit_CommonCls::checkNameFile($strNameFile, $strPathFile, $strFirst, $strLast, $intIndex);
			} else {
				return $strNameFile;
			}
		} else {
			return $strNameFile;
		}
	}
	
	/**-----------------------------------------------------------------------
	 * Check valid date  format 
	 *
	 * @param 	string 		$strDate	Date string
	 * @param	string		$strFormat	Date format (default Y-m-d)
	 * @Return: true/false
	 ------------------------------------------------------------------------*/
	function validateDate($strDate, $strFormat = 'Y-m-d')
	{
		$objDate = DateTime::createFromFormat($strFormat, $strDate);
		if($objDate != false && $objDate->format($strFormat) == $strDate){
			return true;
		}
		return false;
	}
	
	/**----------------------------------------------------------------------
	 * Get all news by account kind
	 *
	 * @param	string	$strNewsKind	News Kind
	 * @return	  array news
	 ------------------------------------------------------------------------*/
	public function getNewsByKind($strNewsKind = '')
	{
		$this->_objConfig = CUnit_Config::getConfig();
		$strFilePath = $this->_objConfig->production->news_folder;

		// if is not dir
		if(is_dir($strFilePath) == false){
			return array();
		}

		// Default get news for all account kind
		if($strNewsKind == ''){
			$strNewsKind = $this->_objConfig->production->news_kind_all;
		}
		
		// Scan directory to get news 's files
		$arrFiles = @scandir($strFilePath);

		// cannot scan directory or empty directory
		if($arrFiles == false){
			return array();
		}

		$arrNews = array();
		// Loop to filter news
		foreach($arrFiles AS $intKey => $strFileName){
			if(strtoupper($strFileName[0]) == $strNewsKind || strtoupper($strFileName[0]) == $this->_objConfig->production->news_kind_all){
				if(file_exists($strFilePath . '/' . $strFileName) == true && is_file($strFilePath . '/' . $strFileName) == true){
					
					$arrFileInfo = explode('_', $strFileName);
					// Check start date, end date and sort is valid
					if(($arrFileInfo[1] == '000000' || ($arrFileInfo[1] != '000000' && $this->validateDate($arrFileInfo[1], 'ymd') == true && strtotime($arrFileInfo[1]) <= strtotime(date("ymd"))))
					&& ($arrFileInfo[2] == '000000' || ($arrFileInfo[2] != '000000' && $this->validateDate($arrFileInfo[2], 'ymd') == true && strtotime($arrFileInfo[2]) >= strtotime(date("ymd"))))
					&& is_numeric($arrFileInfo[3]) == true){
						
						$strFileContent = file_get_contents($strFilePath . '/' . $strFileName);

						if($strFileContent != false){
							// Add to array
							$arrFile = array('Kind'			=> $arrFileInfo[0],
											 'StartDate' 	=> $arrFileInfo[1],
											 'EndDate' 		=> $arrFileInfo[2],
											 'Sort' 		=> $arrFileInfo[3],
											 'Content' 		=> $strFileContent
											);
							$arrNews[] = $arrFile;
						}
					}
				}
			}
		}

		// Sort array by Sort column
		$arrSortNews = $this->arrayOrderBy($arrNews, 'Sort', SORT_ASC);

		return $arrSortNews;
	}
	
	/**-----------------------------------------------------------------------
	 * Sort array by an element in array
	 *
	 * @Return: array
	 ------------------------------------------------------------------------*/
	function arrayOrderBy()
	{
		$arrArgs = func_get_args();
		$arrData = array_shift($arrArgs);
		if(is_array($arrData) == false){
			return array();
		}
	
		$arrSort = array();
		foreach ($arrArgs as $intArrKey => $strField) {
			if (is_string($strField)) {
				$arrTmp = array();
				foreach ($arrData as $intKey => $arrRow){
					$arrTmp[$intKey] = $arrRow[$strField];
				}
				$arrArgs[$intArrKey] = $arrTmp;
			}
			$arrSort[] = &$arrArgs[$intArrKey];
		}
		$arrSort[] = &$arrData;
		call_user_func_array('array_multisort', $arrSort);
		return end($arrSort);
	}
}

